package com.qf;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsGroupon;
import com.qf.service.GrouponService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sunyamei
 * @version V1.0
 * @Project javase2203
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/7/31 15:29
 */
@RequestMapping("/groupon")
@RestController
@CrossOrigin("*")
public class GrouponController {

    @Autowired
    private GrouponService grouponService;

    @RequestMapping("/list")
    public  Object queryByPage(Integer id,Integer page,Integer limit,String sort,String order){

        //调用Service
        IPage<DtsGroupon> ipage = grouponService.queryByPage(id, page, limit, sort, order);

        //查询总条数
        long total = ipage.getTotal();

        //查询总页数
        List<DtsGroupon> list = ipage.getRecords();

        //map封装
        Map<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("items", list);
        return ResponseUtil.ok(data);

    }




}
